import {
	enUS,
	zhCN,
	darkTheme,
	GlobalTheme
} from 'naive-ui'
import { ref, getCurrentInstance, ComponentInternalInstance } from 'vue'
import { useI18n } from 'vue-i18n'

const theme = ref<GlobalTheme | null>(null)
export default () => {
	const { t, locale, } = useI18n({ useScope: 'global', })
	const instance = getCurrentInstance() as ComponentInternalInstance
	instance.root.appContext.config.globalProperties.$t = t
	const changeTheme = () => {
		if (theme.value === null) {
			theme.value = darkTheme as GlobalTheme
		} else {
			theme.value = null
		}
	}
	const changeLocale = () => {
		if (locale.value === 'en') {
			locale.value = 'zh'
		} else {
			locale.value = 'en'
		}
	}
	return {
		theme,
		locale,
		t,
		enUS,
		changeTheme,
		changeLocale,
	}
}
